// 浏览器的前进后退功能
// 1. 面向对象模块化，思想，
// 一个文件就写一个类
// 2.引入其他模块
const {StackBasedLinkedList} = require('./StackBaseOnLinkedList');
console.log(StackBasedLinkedList);
class Browser {
    constructor() {
        this.normalStack = new StackBasedLinkedList();
        this.backstack = new StackBasedLinkedList();
    }
    pushNormal(name) {
        this.normalStack.push(name);  // 浏览网页入栈 
        this.backstack.clear(); //abc b->d c丢失
        this.displayAllStack();
    }
    back() {
        const value = this.normalStack.pop();
        if(value!==-1){
            this.backstack.push(value);
            this.displayAllStack();
        } else {
            console.log('无法后退');
        }  
    }
    front () {
        const value = this.backstack.pop();
        if(value!==-1){
            this.normalStack.push(value);
            this.displayAllStack();
        } else {
            console.log('无法前进');
        }
    }
    displayAllStack() {
        console.log('---后退页面---');
        this.backstack.display();
        console.log('---浏览页面---');
        this.normalStack.display();
    }
}

let browser = new Browser();
browser.pushNormal('www.google.com');
browser.pushNormal('www.baidu.com');
browser.pushNormal('www.github.com');
browser.back();
browser.back();
browser.front();
browser.pushNormal('www.tmall.com');